﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace zlh.Adminyemian
{
    public partial class admintjstu : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Page_PreInit(object sender, EventArgs e)
        {
            if (Session["color"] == "1")
            {
                Page.Theme = "1";

            }
            else if (Session["color"] == "2")
            {
                Page.Theme = "2";
            }
            else
            {
                Page.Theme = "3";
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string strCn = "server=pc.hstc.cn;database=dhd2014112130;uid=2014112130;pwd=19970514";
            SqlConnection cn = new SqlConnection(strCn);

            try
            {
                cn.Open();
                string strsql = "select stuNO from StudentInformation ";
                SqlCommand cmd = new SqlCommand(strsql, cn);
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.Read())//该用户能读到
                {
                    this.lblInfo.Text = "该用户已经存在";//显示错误信息

                }
                else
                {
                    StringBuilder sb = new StringBuilder(1024);
                    sb.Append("INSERT INTO StudentInformation ");
                    sb.Append("                (stuNO, stuName, Gender, Age, College, Major, Class, Memo,Address) ");
                    sb.Append("VALUES   (@stuNO, @stuName, @Gender, @Age, @College,@Major, @Class, @Memo, @Address) ");

                    SqlParameter[] pms = new SqlParameter[9];
                    pms[0] = new SqlParameter("@stuNO", this.stuinfoNo.Text);
                    pms[1] = new SqlParameter("@stuName", this.stuinfoName.Text);
                    pms[2] = new SqlParameter("@Gender", ged.Text);
                    pms[3] = new SqlParameter("@Age", this.agtxt.Text);
                    pms[4] = new SqlParameter("@College", this.coltxt.Text);
                    pms[5] = new SqlParameter("@Major", this.majtxt.Text);
                    pms[6] = new SqlParameter("@Class", this.clatxt.Text);
                    pms[7] = new SqlParameter("@Memo", this.montxt.Text);
                    pms[8] = new SqlParameter("@Address", this.addtxt.Text);

                    int intResult = (int)SqlHelper.ExecuteNonQuery(sb.ToString(), pms);
                    this.lblInfo.Text = (intResult < 1) ? "新增失败！" : "新增" + intResult.ToString() + "条记录！";
                }
            }
            catch { 
            }
        }

        protected void montxt_TextChanged(object sender, EventArgs e)
        {

        }

        protected void stuloginbtn_Click(object sender, EventArgs e)
        {
            string strCn = "server=pc.hstc.cn;database=dhd2014112130;uid=2014112130;pwd=19970514";
            SqlConnection cn = new SqlConnection(strCn);

            try
            {
                cn.Open();
                string strsql = "select studentId from StudentLogin ";
                SqlCommand cmd = new SqlCommand(strsql, cn);
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.Read())//该用户能读到
                {
                    this.lblInfo1.Text = "该用户已经存在";//显示错误信息

                }
                else
                {
                    StringBuilder sb = new StringBuilder(1024);
                    sb.Append("INSERT INTO StudentLogin ");
                    sb.Append("                (studentId ,studentPassword) ");
                    sb.Append("VALUES   (@studentId, @studentPassword) ");

                    SqlParameter[] pms = new SqlParameter[2];
                    pms[0] = new SqlParameter("@studentId", this.stulgNo.Text);
                    pms[1] = new SqlParameter("@studentPassword", this.stulgpsw.Text);

                    int intResult = (int)SqlHelper.ExecuteNonQuery(sb.ToString(), pms);
                    this.lblInfo1.Text = (intResult < 1) ? "新增失败！" : "新增" + intResult.ToString() + "条记录！";
                }
                  }
                catch{

                }
       }
    }
}